<?php

class Page {

    public $content;
    public $title = "TLA Consulting Pty Ltd";
    public $keywords = "TLA Consulting, Three Letter Abbreviation, some of
        my best friends are search engines";
    public $buttons = array(
                        "Home" => "home.php",
                        "Contact" => "contact.php",
                        "Services" => "services.php", 
                        "Site Map" => "map.php"
                    );
    
    public function __set($name, $value) {
        $this->$name = $value;
    }

    public function display() {
        echo "<html>\n<head>\n";
        $this->displayTitle();
        $this->displayKeywords();
        $this->displayStyles();
        echo "</head>\n<body>\n";
        $this->displayHeader();
        $this->displayMenu($this->buttons);
        echo $this->content;
        $this->displayFooter();
        echo "</body>\n</html>\n";
    }

    public function displayTitle() {
        echo "<title>".$this->title."</title>\n";
    }

    public function displayKeywords() {
        echo "<meta name=\"keywords\" content=\"{$this->keywords}\" />\n";
    }

    public function displayStyles() {

    }

    public function displayHeader() {
        echo "<h1>This is header</h1>\n";
    }

    public function displayMenu(array $buttons) {
        echo "<ul>\n";
        while (list($name, $url) = each($buttons)) {
            $this->displayButton($name, $url, !$this->isUrlCurrentBotton($url));
        }
        echo "</ul>\n";
    }

    public function displayButton($name, $url, $active = true) {
        if ($active) {
            echo "<li><a href=\"{$url}\">{$name}</a></li>\n";
        } else {
            echo "<li><a href=\"{$url}\" class=\"active\">{$name}</a></li>\n";
        }
    }

    public function isUrlCurrentBotton($url) {
        if (strpos($_SERVER['PHP_SELF'], $url) === false) {
            return false;
        } else {
            return true;
        }
    }

    public function displayFooter() {
        echo "<p>This is footer</p>\n";
    }
}
